<template>
	<view>
		<totalMask :show.sync="isShow" :showType="showType">
			<view class="nvue-flex">
				<view class="gift-title">
					<text class="title">打赏记录</text>
				</view>
				
				<scroll-view scroll-y class="gift-list" :show-scrollbar="false" @scrolltolower="onLoadMore">
					<view class="gift-view">
						<block v-for="(item, index) in list" :key="index">
							<view class="gift-item">
								<text class="gift-nickname">{{item.user.nickname}}</text>
								<image class="gift-img" :src="item.gift.show_file" mode="heightFix" style="width: 30rpx;"></image>
							</view>
						</block>
					</view>
				</scroll-view>
			</view>
		</totalMask>
	</view>
</template>

<script>
	import storage from "@/utils/storage";
	import {
		receiveGiftList
	} from "@/API/newLive.js";

	export default {
		data() {
			return {
				isShow: false,
				showType: 0,
				page: 1,
				total: 0,
				list: [],
			}
		},
		destroyed() {
			uni.$off("ZBGiftRecords")
		},
		mounted() {
			uni.$on("ZBGiftRecords", () => {
				this.isShow = true
				this.showType = 2
				this.onRefresh()
			})
		},
		methods: {
			/**
			 * 加载更多
			 */
			onLoadMore() {
				if (this.list.length < this.total) {
					this.page++
					this.getData()
				}
			},
			/**
			 * 刷新
			 */
			onRefresh() {
				this.page = 1
				this.list = []
				this.getData()
			},
			/**
			 * 请求
			 */
			async getData() {
				let res = await receiveGiftList({
					room_id: storage.getLiveRoomInfo().id,
					page: this.page
				})
				this.total = res.data.total
				let list = res.data.data
				if (this.page == 1) {
					this.list = list
				} else {
					this.list = [...this.list, ...list]
				}
			}
		},
	}
</script>

<style scoped>
	.gift-title {
		width: 300rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}
	.title {
		color: white;
		font-size: 32rpx;
	}
	.gift-list {
		margin-top: 30rpx;
		width: 750rpx;
		overflow: hidden;
		height: 600rpx;
	}

	.gift-view {
		width: 750rpx;
		display: flex;
		flex-direction: column;
		overflow: hidden;
	}

	.gift-item {
		width: 750rpx;
		padding: 0 35rpx;
		margin-bottom: 40rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		overflow: hidden;
	}

	.gift-nickname {
		color: #FCCE6E;
		font-size: 28rpx;
	}

	.gift-img {
		margin-left: 16rpx;
		height: 30rpx;
	}
</style>